using System.Collections.Generic;
using Bosphorus.Library.Facade.Loader.Castle.Configurator;
using Castle.MicroKernel.Registration;
using Newtonsoft.Json;
using NExt.Serialization.Core;
using NExt.Serialization.JsonNet.Conversion;
using Newtonsoft.Json.Converters;

namespace NExt.Serialization.JsonNet.Configuration
{
    public class ContainerConfigurator : IContainerConfigurator
    {
        public void Configure(Castle.Windsor.IWindsorContainer container)
        {
            var jsonSerializerSettings = new JsonSerializerSettings
                                        {
                                            NullValueHandling = NullValueHandling.Ignore,
                                            ObjectCreationHandling = ObjectCreationHandling.Replace,
                                            ContractResolver = new ContractResolver(),
                                            Converters = new List<JsonConverter>
                                                             {
                                                                 new ScriptConverter(),
                                                                 new AnonymousObjectConvertor(),
                                                                 new ComponentConvertor(),
                                                                 new DateTimeConvertor()
                                                             }
                                        };

            container.Register(
                Component.For<IJsonSerializer>()
                         .ImplementedBy<JsonNetSerializer>()
                         .DependsOn(Property.ForKey("jsonSerializerSettings").Eq(jsonSerializerSettings)));
        }
    }
}